package cn.wolfcode.luowowo.article.controller;

import cn.wolfcode.luowowo.article.domain.Destination;
import cn.wolfcode.luowowo.article.service.IDestinatonService;
import cn.wolfcode.luowowo.common.query.DestinationQueryObject;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/destination")
public class DestinationController {
    @Reference
    private IDestinatonService destinatonService;
    @RequestMapping("/list")
    public String list(Model model,@ModelAttribute("qo") DestinationQueryObject queryObject){
        //查询出所有的目的地,共享给页面
       PageInfo pageInfo =  destinatonService.query(queryObject);
       model.addAttribute("pageInfo",pageInfo);
       //吐司,面包屑数据共享

        model.addAttribute("toasts",destinatonService.getToasts(queryObject.getParentId()));
       return "destination/list";
    }
    //热门相关设置
    @RequestMapping("/changeHotValue")
    @ResponseBody
    public AjaxResult changeHotValue(Boolean hot,Long id){
        //根据hot和id去改变状态
        destinatonService.changeHotState(hot,id);
        return new AjaxResult();
    }
    //编辑
    @RequestMapping("/setInfo")
    @ResponseBody
    public AjaxResult setInfo(Destination destination){
        //根据info和id去修改内容
        destinatonService.updateInfoById(destination);
        return new AjaxResult();
    }
}
